import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true
	},
	{
		path: '/',
		component: Layout,
		redirect: '/dashboard',
		children: [{
			path: 'dashboard',
			component: () => import('@/views/dashboard/index'),
			name: 'Dashboard',
			meta: {
				title: 'Dashboard',
				icon: 'dashboard',
				affix: true
			}
		}]
	},
	{
		path: '/lietou',
		component: Layout,
		redirect: '/lietouList',
		children: [{
				path: '/lietouList',
				name: 'LietouList',
				component: () => import('@/views/lietou/lietouList'),
				meta: {
					title: '猎头列表',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/lietouDetail',
				name: 'LietouDetail',
				component: () => import('@/views/lietou/listDetail/lietouDetail'),
				meta: {
					title: '猎头详情',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/lietouWokersList',
				name: 'LietouWokersList',
				component: () => import('@/views/lietou/listDetail/lietouWokersList'),
				meta: {
					title: '工人名单',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/lietouDetailAcount',
				name: 'LietouDetailAcount',
				component: () => import('@/views/lietou/listDetail/lietouDetailAcount'),
				meta: {
					title: '账户流水',
					icon: 'dashboard',
					noCache: true
				}
			},
			{
				path: '/lietouLiepinList',
				name: 'LietouLiepinList',
				component: () => import('@/views/lietou/listDetail/lietouLiepinList'),
				meta: {
					title: '猎聘记录',
					icon: 'dashboard',
					noCache: true
				}
			},
			{
				path: '/lietouLaheiHistory',
				name: 'LietouLaheiHistory',
				component: () => import('@/views/lietou/lietouLaheiHistory'),
				meta: {
					title: '拉黑记录',
					icon: 'dashboard',
					noCache: true
				}
			},
			{
				path: '/lietouManage',
				name: 'LietouManage',
				component: () => import('@/views/lietou/lietouManage'),
				meta: {
					title: '发展猎头',
					icon: 'dashboard',
					noCache: true
				}
			}
		]
	},
	{
		path: '/company',
		component: Layout,
		redirect: '/companyList',
		children: [{
				path: '/companyList',
				name: 'CompanyList',
				component: () => import('@/views/company/companyList'),
				meta: {
					title: '公司列表',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/companyDetail',
				name: 'CompanyDetail',
				component: () => import('@/views/company/companyDetail'),
				meta: {
					title: '公司详情',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/companyExamine',
				name: 'CompanyExamine',
				component: () => import('@/views/company/companyExamine'),
				meta: {
					title: '审核中心',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/companyExaDetail',
				name: 'CompanyExaDetail',
				component: () => import('@/views/company/companyExaDetail'),
				meta: {
					title: '审核中心详情',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/companyToBack',
				name: 'CompanyToBack',
				component: () => import('@/views/company/companyToBack'),
				meta: {
					title: '拉黑记录',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/companyDevelop',
				name: 'CompanyDevelop',
				component: () => import('@/views/company/companyDevelop'),
				meta: {
					title: '发展用工中心',
					icon: 'dashboard',
					noCache: false
				}
			}
		]
	},
	{
		path: '/position',
		component: Layout,
		redirect: '/positionManage',
		children: [{
				path: '/positionManage',
				name: 'PositionManage',
				component: () => import('@/views/position/positionManage'),
				meta: {
					title: '职位招聘列表',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/positionDetail',
				name: 'PositionDetail',
				component: () => import('@/views/position/positionDetail'),
				meta: {
					title: '职位招聘详情',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/positionEdit',
				name: 'PositionEdit',
				component: () => import('@/views/position/positionEdit'),
				meta: {
					title: '职位招聘详情',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/positionEditTree',
				name: 'PositionEditTree',
				component: () => import('@/views/position/positionEditTree'),
				meta: {
					title: '编辑分类下级',
					icon: 'dashboard',
					noCache: false
				}
			}
		]
	},
	{
		path: '/finace',
		component: Layout,
		redirect: '/finaceManage',
		children: [{
				path: '/finaceManage',
				name: 'FinaceManage',
				component: () => import('@/views/finace/finaceManage'),
				meta: {
					title: '账户管理',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/finaceDetail',
				name: 'FinaceDetail',
				component: () => import('@/views/finace/finaceDetail'),
				meta: {
					title: '编辑我的银行卡',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/finaceLietou',
				name: 'FinaceLietou',
				component: () => import('@/views/finace/finaceLietou'),
				meta: {
					title: '猎头提现管理',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/finaceAgent',
				name: 'FinaceAgent',
				component: () => import('@/views/finace/finaceAgent'),
				meta: {
					title: '代理商提现管理',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/finaceRecharge',
				name: 'FinaceRecharge',
				component: () => import('@/views/finace/finaceRecharge'),
				meta: {
					title: '用工公司充值记录',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/finaceTicket',
				name: 'FinaceTicket',
				component: () => import('@/views/finace/finaceTicket'),
				meta: {
					title: '发票管理',
					icon: 'dashboard',
					noCache: false
				}
			}
		]
	},
	{
		path: '/city',
		component: Layout,
		redirect: '/cityPartner',
		children: [{
				path: '/cityPartner',
				name: 'CityPartner',
				component: () => import('@/views/city/cityPartner'),
				meta: {
					title: '代理商列表',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/cityPartnerDetail',
				name: 'CityPartnerDetail',
				component: () => import('@/views/city/cityPartnerDetail'),
				meta: {
					title: '代理商详情',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/cityClearHistory',
				name: 'CityClearHistory',
				component: () => import('@/views/city/cityClearHistory'),
				meta: {
					title: '代理商详情',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/cityChangeHistory',
				name: 'CityChangeHistory',
				component: () => import('@/views/city/cityChangeHistory'),
				meta: {
					title: '分佣调整记录',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/cityLietouList',
				name: 'CityLietouList',
				component: () => import('@/views/city/cityLietouList'),
				meta: {
					title: '名下猎头列表',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/cityCompanyList',
				name: 'CityCompanyList',
				component: () => import('@/views/city/cityCompanyList'),
				meta: {
					title: '名下企业列表',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/cityAcount',
				name: 'CityAcount',
				component: () => import('@/views/city/cityAcount'),
				meta: {
					title: '账户流水',
					icon: 'dashboard',
					noCache: false
				}
			}
		]
	},
	{
		path: '/inner',
		component: Layout,
		redirect: '/innerManage',
		children: [{
				path: '/innerManage',
				name: 'InnerManage',
				component: () => import('@/views/inner/innerManage'),
				meta: {
					title: '内部管理',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/innerFankui',
				name: 'InnerFankui',
				component: () => import('@/views/inner/innerFankui'),
				meta: {
					title: '意见反馈',
					icon: 'dashboard',
					noCache: false
				}
			},
			{
				path: '/innerPercent',
				name: 'InnerPercent',
				component: () => import('@/views/inner/innerPercent'),
				meta: {
					title: '内部分佣管理',
					icon: 'dashboard',
					noCache: false
				}
			}
		]
	},
	{
		path: '/manage',
		component: Layout,
		redirect: '/manageCity',
		children: [{
			path: '/manageCity',
			name: 'ManageCity',
			component: () => import('@/views/manage/manageCity'),
			meta: {
				title: '城市管理',
				icon: 'dashboard',
				noCache: false
			}
		}]
	},
	{
		path: '/404',
		component: () => import('@/views/error-page/404'),
		hidden: true
	},
	{
		path: '*',
		redirect: '/404',
		hidden: true
	}
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
	// 	{
	//   path: '/permission',
	//   component: Layout,
	//   redirect: '/permission/page',
	//   alwaysShow: true, // will always show the root menu
	//   name: 'Permission',
	//   meta: {
	//     title: 'Permission',
	//     icon: 'lock',
	//     roles: ['admin', 'editor'] // you can set roles in root nav
	//   },
	//   children: [{
	//     path: 'page',
	//     component: () => import('@/views/permission/page'),
	//     name: 'PagePermission',
	//     meta: {
	//       title: 'Page Permission',
	//       roles: ['admin'] // or you can only set roles in sub nav
	//     }
	//   },
	//   {
	//     path: 'role',
	//     component: () => import('@/views/permission/role'),
	//     name: 'RolePermission',
	//     meta: {
	//       title: 'Role Permission',
	//       roles: ['admin']
	//     }
	//   }
	//   ]
	// },

	// {
	//   path: '/error',
	//   component: Layout,
	//   redirect: 'noRedirect',
	//   name: 'ErrorPages',
	//   meta: {
	//     title: 'Error Pages',
	//     icon: '404'
	//   },
	//   children: [{
	//     path: '401',
	//     component: () => import('@/views/error-page/401'),
	//     name: 'Page401',
	//     meta: {
	//       title: '401',
	//       noCache: true
	//     }
	//   },
	//   {
	//     path: '404',
	//     component: () => import('@/views/error-page/404'),
	//     name: 'Page404',
	//     meta: {
	//       title: '404',
	//       noCache: true
	//     }
	//   }
	//   ]
	// },

	// {
	//   path: '/error-log',
	//   component: Layout,
	//   children: [{
	//     path: 'log',
	//     component: () => import('@/views/error-log/index'),
	//     name: 'ErrorLog',
	//     meta: {
	//       title: 'Error Log',
	//       icon: 'bug'
	//     }
	//   }]
	// },

	// // 404 page must be placed at the end !!!
	// {
	//   path: '*',
	//   redirect: '/404',
	//   hidden: true
	// }
]

const createRouter = () => new Router({
	// mode: 'history', // require service support
	scrollBehavior: () => ({
		y: 0
	}),
	routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}

export default router
